package net.trustie.model;
import net.trustie.utils.DateHandler;
import net.trustie.utils.StringHandler;
import us.codecraft.webmagic.model.annotation.ExtractBy;
import core.AfterExtractor;
import core.Page;
import core.ValidateExtractor;

public class bytes_Model implements AfterExtractor, ValidateExtractor {

	private String Url =" ";

	private int history = 0;

	private String extractTime = "";

	@ExtractBy("/html/body/table[1]/tbody/tr/td/table/tbody/tr/td[3]/div/ul/li[3]/span/text()")
	private String postTime;
	@ExtractBy("/html/body/table[1]/tbody/tr/td/table/tbody/tr/td[3]/div/ul/li[2]/span/text()")
	private String replyNum = "";
	@ExtractBy("/html/body/table[1]/tbody/tr/td/table/tbody/tr/td[3]/div/ul/li[1]/span/text()")
	private String viewNum="";
@ExtractBy("/html/body/table[1]/tbody/tr/td/h1/a/text()")
	private String questionTitle = "";

	@ExtractBy("//*div[@style='font-size: 105%; margin: 15px 0px 0px 0px; line-height: 20px; word-wrap: break-word;']/allText()")
	private String  questionContent = "";

	@ExtractBy("//*div[@style='margin: 0px 0px 0px 15px; width: 505px;']/div[1]/span/a[@class='bigusername']/text()")
	private String author = "";

	

	public void afterProcess(Page page) {
		// 处理帖子的url
		this.Url= page.getPageUrl();

		// 处理帖子的回复次数
		this.replyNum = StringHandler.subString(this.replyNum, "replies: ");

		//处理帖子的浏览次数
		this.viewNum = StringHandler.subString(this.viewNum, "viewed: ");

       // 处理帖子的提交时间
		this.postTime = DateHandler.formatAllTypeDate(this.postTime,page.getTime());

		// 处理extractorTime
		this.extractTime = DateHandler.getExtractTime();

	}

	public void validate(Page page) {
		if (StringHandler.isAtLeastOneBlank(this.questionTitle, this.author, this.Url)) {
			page.setResultSkip(this, true);
			return;
		}

		if (!StringHandler.canFormatterInteger(this.replyNum, this.viewNum)) {
			page.setResultSkip(this, true);
			return;
		}

		if (!DateHandler.canFormatToDate(this.postTime, this.extractTime)) {
			page.setResultSkip(this, true);
		}	
		
	}

	
	public String getTopicUrl() {
		return Url;
	}

	public void setTopicUrl(String topicUrl) {
		this.Url = topicUrl;
	}

	
	public String getTopicTitle() {
		return questionTitle;
	}

	public void setTopicTitle(String topicTitle) {
		this.questionTitle = topicTitle;
	}

	public String getTopicContent() {
		return questionContent;
	}

	public void setTopicContent(String topicContent) {
		this.questionContent = topicContent;
	}

	public String getTopicScore() {
		return viewNum;
	}

	public void setTopicScore(String topicScore) {
		this.viewNum = topicScore;
	}

	public String getReplyNum() {
		return replyNum;
	}

	public void setReplyNum(String replyNum) {
		this.replyNum = replyNum;
	}

	public String getAuthor() {
		return author;
	}

	public String getUrl() {
		return Url;
	}

	public void setUrl(String url) {
		Url = url;
	}

	public String getViewNum() {
		return viewNum;
	}

	public void setViewNum(String viewNum) {
		this.viewNum = viewNum;
	}

	public String getQuestionTitle() {
		return questionTitle;
	}

	public void setQuestionTitle(String questionTitle) {
		this.questionTitle = questionTitle;
	}

	public String getQuestionContent() {
		return questionContent;
	}

	public void setQuestionContent(String questionContent) {
		this.questionContent = questionContent;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	
	public String getPostTime() {
		return postTime;
	}

	public String getExtractorTime() {
		return extractTime;
	}

	
	public void setPostTime(String postTime) {
		this.postTime = postTime;
	}

	public void setExtractorTime(String extractorTime) {
		this.extractTime = extractorTime;
	}


	public int getHistory() {
		return history;
	}

	public void setHistory(int history) {
		this.history = history;
	}


	public String getExtractTime() {
		return extractTime;
	}

	

	public void setExtractTime(String extractTime) {
		this.extractTime = extractTime;
	}

}

